package com.xinchuang.service.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xinchuang.comment.R;
import com.xinchuang.service.UserModService;
import com.xinchuang.utils.CheckUtil;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.text.SimpleDateFormat;

import com.xinchuang.utils.DateUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;

@Service
public class UserModServiceImpl implements UserModService {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public String addUser(JSONObject jsonObject) {
        //jsonobject解析获取用户名
        String username = jsonObject.getString("username");
        //jsonobject解析获取密码
        String password = jsonObject.getString("password");
        //jsonobject解析获取角色Id
        String roleId = jsonObject.getString("roleId");
        if (
                "wangxx".equals(username)
                        &&
                        "11111".equals(password)
                        &&
                        "1".equals(roleId)
        ) {
            return "{\"code\":200,\"data\":{},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String editUser(JSONObject jsonObject) {
        //jsonobject解析获取用户名
        String username = jsonObject.getString("username");
        //jsonobject解析获取密码
        String password = jsonObject.getString("password");
        //jsonobject解析获取角色Id
        String roleId = jsonObject.getString("roleId");
        //jsonobject解析获取用户ID
        String UID = jsonObject.getString("UID");
        if (
                "wangxx".equals(username)
                        &&
                        "11111".equals(password)
                        &&
                        "1".equals(roleId)
                        &&
                        "1".equals(UID)
        ) {
            return "{\"msg\":\"修改成功\",\"code\":200,\"data\":{},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String delUser(JSONObject jsonObject) {
        //jsonobject解析获取uid
        String uid = jsonObject.getString("uid");
        if (
                "1".equals(uid)
        ) {
            return "{\"msg\":\"删除成功\",\"code\":200,\"data\":{},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String userList(JSONObject jsonObject) {
        //jsonobject解析获取用户名
        String username = jsonObject.getString("username");
        //jsonobject解析获取页码
        String pageNum = jsonObject.getString("pageNum");
        if (
                "1".equals(pageNum)
        ) {
            return "{\"data\":[{\"password\":\"111111\",\"roleId\":\"1\",\"roleName\":\"项目经理\",\"username\":\"wangxx\"},{\"password\":\"222222\",\"roleId\":\"2\",\"roleName\":\"调试工\",\"username\":\"tiaoxx\"}]}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

}
